package com.personal.dao;

import com.personal.domain.HouseProp;
import com.personal.domain.HousePropPlus;
import com.personal.util.partDisplay.HousePropPart;
import org.apache.ibatis.annotations.*;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

/**
 * @projectName: smartCommunity_springboot
 * @package: com.personal.dao
 * @className: HousePropDao
 * @author: bong~
 * @description: TODO
 * @date: 2023/8/10 16:27
 * @version: 1.0
 */

@Mapper
public interface HousePropDao {

    @Select("select * from housepropetry")
    List<HouseProp> selectAll();


    @Select("select id,parkAreaId,customerType,customerName,owner,objectType,telephone,historicalCustomer,fromContract," +
            "remark,startChargingDate,endChargingDate,handHouseDate,startChargingDate,endLeaseDate,signDate,transferDate,importDate from housepropetry")
    List<HousePropPart> selectPartAll();

    @Select("select id,parkAreaId,customerType,customerName,owner,objectType,telephone,historicalCustomer,fromContract," +
            "remark,startChargingDate,endChargingDate,handHouseDate,startChargingDate,endLeaseDate,signDate,transferDate,importDate from housepropetry where " +
            "customerName like CONCAT('%',#{name},'%') and customerType like CONCAT('%',#{type},'%')" )
    List<HousePropPart> selectPartByKey(String name,String type);

    /*房产模块添加，需要同时对三张表进行操作*/
    //添加房产信息
    @Insert("insert into housepropetry (id, parkAreaId,owner,objectType,startChargingDate, endChargingDate, customerName," +
            "                           customerType, handHouseDate, startLeaseDate, endLeaseDate, signDate, transferDate," +
            "                           telephone, importDate, historicalCustomer, fromContract, remark) VALUE" +
            "                           (null,#{parkAreaId},#{owner},#{objectType},#{startChargingDate},#{endChargingDate},#{customerName}," +
            "                           #{customerType},#{handHouseDate},#{startLeaseDate},#{endLeaseDate},#{signDate},#{transferDate}," +
            "                           #{telephone},#{importDate},#{historicalCustomer},#{fromContract},#{remark})")
    int add(HouseProp houseProp);
    //修改房产的占用情况
    @Update("update parkarea set status=-status where id=#{parkAreaId}")
    int upStatusParkArea(int parkAreaId);
    //添加房产与客户的关联关系
    @Insert("insert into customerhousepropetry (id,customerId,customerType,parkAreaId) values " +
            "(null,#{customerId},#{customerType},#{parkAreaId})")
    int upRelHouseProp(int customerId,String customerType,int parkAreaId);



    @Select("select * from housepropetry where id=#{id}")
    HouseProp getUpdateData(int id);
    @Update("update housepropetry set objectType=#{objectType},owner=#{owenr}," +
            "                         startChargingDate=#{startChargingDate},endChargingDate=#{endChargingDate}," +
            "                         handHouseDate=#{handHouseDate}," +
            "                         startLeaseDate=#{startChargingDate},endChargingDate=#{endChargingDate},signDate=#{signDate}," +
            "                         transferDate=#{transferDate},telephone=#{telephone},importDate=#{importDate},historicalCustomer=#{historicalCustomer}," +
            "                         fromContract=#{fromContract},remark=#{remark} where id=#{id}")
    int update(HouseProp houseProp);

//    ------------------------------------------------------------------

    /*房产信息的删除模块，联系到两张表*/
    //根据房产信息id获取房产parkAreaId,进而改变房产的占用情况
    @Select("select parkAreaId from housepropetry where id=#{id}")
    int getParkAreaIdById(int id);
    //改变房产占用情况可服用上述添加模块中的upStatusParkArea函数

    //删除客户房产信息关联表
    @Delete("delete from customerhousepropetry where parkAreaId=#{parkAreaId}")
    int deleteRelHouseProp(int parkAreaId);
    //  删除房产表信息
    @Delete("delete from housepropetry  where id=#{id}")
    int delete(int id);



    //点击目录树，获取parkAreaId的list
    @Select("select * from housepropetry where parkAreaId=#{parkAreaId}")
    HousePropPart selectByAreaId(Integer parkAreaId);







}
